#include "chattext.h"
#include "../main/mainwindow.h"

ChatText::ChatText(QWidget* parent)
    :QTextEdit(parent)
{

}
/**
 * @brief ChatText::keyReleaseEvent 点击发送聊天内容
 * @param e
 */
void ChatText::keyReleaseEvent(QKeyEvent *e){
    if(e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return){
        QString content = this->toPlainText();
        MainWindow *mainPtr = (MainWindow*)parent()->parent()->parent()->parent();
        mainPtr->chat->sendMsg(content);

        //清空
        this->clear();
    }
}

void ChatText::mousePressEvent(QMouseEvent *m){
    MainWindow *mainPtr = (MainWindow*)parent()->parent()->parent()->parent();
    int uid = mainPtr->chat->getCurrentClickedItem()->userProfile.uid;
    mainPtr->chat->refreshItemUnreadNum(uid, "");
    mainPtr->chat->clearUnreadNum(uid);
    QString unreadAllNum = mainPtr->chat->getAllUnreadTotalNumStr();
    mainPtr->refreshAllUnreadNum(unreadAllNum);
}
